/*
 * Copyright (c) 2013.
 * 游戏服务器核心代码编写人陈磊拥有使用权
 * 联系方式：E-mail:13638363871@163.com ;qq:502959937
 * 个人博客主页：http://my.oschina.net/chenleijava
 */

package com.dc.gameserver.serverCore.service.battle.coreBattleLogic.differentCardType;

import com.dc.gameserver.baseConfig.Config;
import com.dc.gameserver.hardCode.CardType;
import com.dc.gameserver.serverCore.service.battle.GameFormula;
import com.dc.gameserver.serverCore.service.battle.coreBattleLogic.AbstractDifferentLogic;
import com.dc.gameserver.serverCore.service.cardModule.CardBox;
import com.dc.gameserver.serverCore.service.cardModule.CardBoxManager;
import com.dc.gameserver.serverCore.service.character.GameCharacter;
import org.springframework.stereotype.Service;

/**
 * @author 石头哥哥</br>
 *         Project : gameServer1.1</br>
 *         Date: 13-11-2  11</br>
 *         Time: 下午4:47</br>
 *         Connect: 13638363871@163.com</br>
 *         packageName: Server.ServerCore.Service.fightProcess.differentCardType</br>
 *         注解：24  防御+技能
 */
@Service
public class d_defence_magic extends AbstractDifferentLogic {


    @Override
    public void PostConstruct() {
        IDIFFERENTS[Integer.parseInt(CardType.DEFENCE_TYPE.getType()+""+CardType.MAGIC_TYPE.getType())]=this;
    }


    /**
     * 处理不同类型牌的逻辑
     * @param p1   优先级高的玩家   defencePlayer
     * @param p2   优先级低的玩家    magicPlayer
     */
    @Override
    public void differentLogicHandle(GameCharacter p1,GameCharacter p2) {
        CardBox cardBox= CardBoxManager.getCardBoxByID(p1.getCardBoxID());
        CardBoxManager.DeffenceCompute(p1);
        cardBox.flushBloodAndMagic();
        //p2 法力有效 ，p1 hurt
        //p1 hurt ,p2 active
        int p1Hurt=0;  //p1 造成的伤害
        int p1Shield=p1.getCurrentShield();
//        int p1Blood=p1.getCurrentBlood();
        int p1Defence=p1.getDefence();
        int p2FiveTypeSkillValue=p2.getFiveTypeSkillValue();
        /**p2--attack-->p1*****/
        int garms= GameFormula.grams(p2.getSkillfiveType(), p1.getSelfFiveType());

        if (garms== 0x1){
            p1Hurt= GameFormula.magicHurtWithGrams(p1Defence, p2FiveTypeSkillValue);
        }else if (garms== 0x2){
            p1Hurt=GameFormula.magicHurtWithUnGrams(p1Defence, p2FiveTypeSkillValue);
        } else {
            p1Hurt=GameFormula.magicHurtWithGramsed(p1Defence, p2FiveTypeSkillValue);
        }
        if (p1Hurt<=0){
            p1Hurt=0;
            p1Hurt= Config.DEFAULT_VALUE.GAME_VALUE.hurt;
        }
        //p2 法力值消耗
        int p2Magic=GameFormula.computeMagicUse(p2); // notify
        if (p2Magic!=0){
            p2.setCurrentMagic(p2.getCurrentMagic()-p2Magic);
        }

//        if (p1Shield>p1Hurt){
//            p1.setCurrentShield(p1Shield-p1Hurt);
//        } else {
//            if (p1Shield==0){
//                p1.setCurrentBlood(p1Blood-p1Hurt);
//            }else {
//                p1.setCurrentBlood(p1Blood+p1Shield-p1Hurt);
//                p1.setCurrentShield(0);
//            }
//        }
        p1.setCurrentShield(p1Shield-p1Hurt);
        cardBox.sendHurtRule(p1.getID(),p1Hurt,p2.getBattleSkillID());
        if (p1.getCurrentShield()<=0){
            p1.setCurrentShield(0);
//            p1.setCurrentBlood(0);
            //被攻击掉血
            cardBox.flushBloodAndMagic();
            cardBox.notifyPkResult(p2);
            CardBoxManager.clearPkResourceWithRoundOver(cardBox.getCardBoxID());
        } else {
            cardBox.flushBloodAndMagic();
            cardBox.resetRoundResource();
        }
    }
}
